//
//  XLViewController.m
//  XLCarPlateInputView
//
//  Created by 10150820867@qq.com on 08/01/2022.
//  Copyright (c) 2022 10150820867@qq.com. All rights reserved.
//

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;
#define StrongSelf(strongSelf) __strong __typeof(&*self) strongSelf = weakSelf;
/// 屏幕宽度
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
/// 屏幕高度
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

/// 状态栏高度  20  44
#define StatusBarHeight      [[UIApplication sharedApplication] statusBarFrame].size.height
/// 顶部安全区域远离高度
#define kTopBarSafeHeight  (StatusBarHeight>20?(44.0):(0))
/// 底部安全区域远离高度
#define kBottomSafeHeight  (StatusBarHeight>20?(34.0):(0))
/// 导航高度
#define NavBarHeight          44.f
/// 底部TabBar高度
#define TabBarHeight          (StatusBarHeight>20?83:49)
/// 导航整体高度
#define NaviHeight             (StatusBarHeight + NavBarHeight)

#import "XLViewController.h"
#import "XLCarPlateInputView.h"
@interface XLViewController ()

@property (weak, nonatomic) IBOutlet UITextField *carPlateTextField;
@end

@implementation XLViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat inputHeight = kBottomSafeHeight + 300;
    CGRect inputRect = CGRectMake(0, SCREEN_HEIGHT - inputHeight, SCREEN_WIDTH, inputHeight);
    XLCarPlateInputView *inputView = [[XLCarPlateInputView alloc] initWithFrame:inputRect];
    inputView.carPlate = self.carPlateTextField.text;
    self.carPlateTextField.inputView = inputView;
    [self.carPlateTextField reloadInputViews];
    WS(weakSelf);
    inputView.doneButtonBlock = ^(NSString *stringValue) {
        StrongSelf(strongSelf);
        [strongSelf carPlateInputDone:stringValue];
    };
    
    inputView.cancelButtonBlock = ^{
        StrongSelf(strongSelf);
        [strongSelf carPlateInputCancel];
    };
    
    inputView.specialButtonBlock = ^{
        StrongSelf(strongSelf);
        [strongSelf carPlateInputSpecial];
    };
}

- (void)carPlateInputDone:(NSString *)stringValue
{
    [self.view.window endEditing:YES];
    self.carPlateTextField.text = stringValue;
    [self.carPlateTextField resignFirstResponder];
}

- (void)carPlateInputCancel
{
    [self.carPlateTextField resignFirstResponder];
}

- (void)carPlateInputSpecial
{
    [self.view.window endEditing:YES];
    self.carPlateTextField.inputView = nil;
    [self.carPlateTextField becomeFirstResponder];
    [self.carPlateTextField reloadInputViews];
   
}


@end
